#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int islandPerimeter(vector<vector<int>>& grid) {
        int l = 0, i = 0, j = 0;
        int row = grid.size();
        int col = grid[0].size();
        vector<vector<int>> book(row, vector<int>(col, 0));
        for (i = 0; i < row; i++)
        {
            for (j = 0; j < col; j++)
            {
                if (grid[i][j] == 1)
                {
                    l += 4;
                    if (i > 0 && grid[i - 1][j] == 1)
                    {
                        l -= 2;
                    }
                    if (j > 0 && grid[i][j - 1] == 1)
                    {
                        l -= 2;
                    }
                }
            }
        }

        return l;
    }
};